package homework;

import java.util.Objects;

public class Student  implements Comparable<Student>{
    private Integer sid;
    private String name;
    private String major;

    // 无参构造器
    public Student() {}

    // 全参构造器
    public Student(Integer sid, String name, String major) {
        this.sid = sid;
        this.name = name;
        this.major = major;
    }

    // getter和setter方法
    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    // 默认排序规则：根据学号升序排列
    @Override
    public int compareTo(Student other) {
        return this.sid.compareTo(other.sid);
    }

    // toString方法
    @Override
    public String toString() {
        return "Student{sid=" + sid + ", name='" + name + "', major='" + major + "'}";
    }

    // equals方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(sid, student.sid) &&
                Objects.equals(name, student.name) &&
                Objects.equals(major, student.major);
    }

    // hashCode方法
    @Override
    public int hashCode() {
        return Objects.hash(sid, name, major);
    }


}
